#!/usr/bin/env python
#
# Copyright 2008 Allen Hutchison (allen@hutchison.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# $URL$
__version__ = "$Rev$"
__author__ = "Allen Hutchison (allen@hutchison.org)"

import logging

from lib.request_handler import BaseRequest
from lib.store_status import StoreStatus

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class StoreStatusPage(BaseRequest):
  """Store the status of all the current scrapers.

  This script handles all requests for status.severedelays.org/*/storestatus
  """
  def get(self, path):
    ss = StoreStatus()
    ss.storeStatusValues();
    format = self.request.get('format')
    logging.info('Page Request for format=%s and path=%s' % 
      ((format or 'None'), path))
    if ('debug' == format):
      logging.info("Debug request for storestatus.")
      template_values = {'ss': ss}
      self.generate(template_name='storestatus.html',
                    template_values=template_values)
    else:
      logging.info("Normal request for storestatus.")

application = webapp.WSGIApplication([('/(.*/)*storestatus', StoreStatusPage)])

def main():
  run_wsgi_app(application)

if __name__ == '__main__':
  main()
  